package com.example.demo.contrller;

import com.example.demo.contrller.data.ReturnData;
import com.example.demo.contrller.vo.RegisterUser;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {
//    @Autowired
//    UserDao userDao;
    @Autowired
    UserService userservice;
    @GetMapping("getUser")
    public ReturnData getUser(HttpServletRequest request){
        String token = request.getHeader("token");
        return userservice.getUser(token);
    }
    @PostMapping ("login")
    public ReturnData login(@RequestBody RegisterUser user) {
        //return userDao.findById(id).get();
        return userservice.login(user.getUsername(),user.getPassword());
    }
     /*
     登录接口
     */
    @PostMapping("register")
    public ReturnData register(@RequestBody RegisterUser user){
        return userservice.register(user);
    }
    @PostMapping("updateUserInfo")
    public ReturnData updateUserInfo(@RequestBody RegisterUser user,HttpServletRequest request){
        String token = request.getHeader("token");
        return userservice.updateUserInfo(user,token);
    }
    @PostMapping("getCode")
    public ReturnData getCode(String email){

        return userservice.getCode(email);
    }

}
